package com.hs.teachsystem;

import com.hs.teachsystem.dao.UserMapper;
import com.hs.teachsystem.model.User;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * Created by MaiBenBen on 2017/7/14.
 */
public class UserService extends Service{
    @Autowired
    UserMapper userMapper;
    /**
     * 登陆
     * @param user
     * @return
     */
    public Map<String,Object> login(User user){
        User correct=null;
        try {
            correct=userMapper.selectByPrimaryKey(user.getrID());
        }catch (Exception e){
            e.printStackTrace();
            return createServiceMap("202",null,"系统错误","login");
        }
        //判断用户是否存在
        if(correct==null){
            return createServiceMap("201",null,"用户不存在","login");
        }else {
            //判断密码
            if(correct.getPassword().equals(user.getPassword())){
                String view=null;
                int roleID=correct.getrID();
                //根据角色的不同选择对应的首页
                if(roleID==0)
                    view="/super/index";
                else if(roleID==1)
                    view="/manager/index";
                else if(roleID==2)
                    view="/teacher/index";
                else
                    view="/student/index";
                return createServiceMap("200",null,"",view);
            }else {
                return createServiceMap("201",null,"密码输入有误","login");
            }
        }
    }

    /**
     * 添加用户
     * @param user
     * @return
     */
    public Map<String,Object> addUser(User user){
        return null;
    }

    /**
     * 删除用户
     * @return
     */
    public Map<String,Object> deleteUser(){
        return null;
    }
    /**
     * 查询用户信息
     * @return
     */
    public Map<String,Object> queryUser(User user){
        return null;
    }

    /**
     * 完善个人信息
     * @param user
     * @return
     */
    public Map<String,Object> updateUserInfo(User user){
        return  null;
    }

    /**
     * 忘记密码
     * @param user
     * @return
     */
    public Map<String,Object> forgetPassword(User user){
        return null;
    }
}
